/* 278. 第一个错误的版本 */
/**
 * Definition for isBadVersion()
 *
 * @param {integer} version number
 * @return {boolean} whether the version is bad
 * isBadVersion = function(version) {
 *     ...
 * };
 */

/**
 * @param {function} isBadVersion()
 * @return {function}
 */
var solution = function (isBadVersion) {
	/**
	 * @param {integer} n Total versions、
	 * @return {integer} The first bad version
	 */

	return function (n) {
		let left = 1,
			right = n
		while (left <= right) {
			const mid = left + ((right - left) >> 1)
			if (isBadVersion(mid)) {
				right = mid - 1
			} else {
				left = mid + 1
			}
		}

		return left
	}
}
